﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;

namespace 字符串
{
    class Program
    {
        public enum ee
        {
            eee = 1
        }
        static void Main(string[] args)
        {
            var tt = int.MaxValue;
            var t = 1 << 00;
            var co = Convert.ToString(t, 2);
          //  Console.WriteLine(Convert.ToString(t,2));

            var b = (1 & 3) == 3;
            var c = (1 & 1) ==1;
            
            Console.WriteLine(b);
            Console.WriteLine(c);



            //安全得字符串对象
            //using (SecureString secure = new SecureString())
            //{
            //    while (true)
            //    {
            //        ConsoleKeyInfo cs = Console.ReadKey();
            //        if (cs.Key == ConsoleKey.Enter) break;
            //        secure.AppendChar(cs.KeyChar);


            //    }
            //    Console.WriteLine();
            //    Display(secure);
            //}


            // var t = ((int)ee.eee).ToString();
            //  System.Console.WriteLine(t);

            //var t = "12345";
            //var tt = t.Substring(2, t.Length - 2);
            //System.Console.WriteLine(tt);

            //getList();
            //GetInsertSQL();
            // getint(100);
            //Parallel.For(0, 1000000, (i,c) => {
            //    Console.WriteLine(i);
            //});

            // Console.WriteLine(0xc29);

            //string str = "sdfoskdf";
            //// Console.WriteLine(str.Substring(str.Length-3,3));//.Split(str.Length - 4)
            //string s = "1,2,3,4,5";
            //string[] p = s.Split(',');

            ////dsfads 
            //str.Reverse();

            //if (s.Contains("2") && !s.Contains("3"))
            //{

            //}
            //foreach (var item in p)
            //{
            //    Console.WriteLine(item);
            //}
            // InserImage(str);
        }

        /// <summary>
        /// 访问非托管内存
        /// </summary>
        /// <param name="ss"></param>
        private unsafe static void Display(SecureString ss)
        {
            Char* pc = null;
            try
            {
                //将  SecureString 解密到一个非托管内存缓冲区中
                pc = (Char*)Marshal.SecureStringToCoTaskMemUnicode(ss);
                for (int i = 0; pc[i]!=0; i++)
                {
                    Console.WriteLine(pc[i]);
                }
            }
            finally
            {
                if (pc!=null)
                {
                    Marshal.ZeroFreeCoTaskMemUnicode((IntPtr)pc);
                }
            }
           
        }



        /// <summary>
        ///
        /// </summary>
        /// <param name="a"></param>
        /// <returns></returns>
        public static void getint(int a)
        {
            /*
            问题： 求一个数的所有因数， 例如 4 有 1，4，2，2 
            然后找出最接近的因子对   2,2
             */
            string num = string.Empty;
            var num1 = int.MaxValue;
            var st = string.Empty;
            var sts = string.Empty;
            System.Collections.Generic.Dictionary<int, int> vs = new System.Collections.Generic.Dictionary<int, int>();
            System.Collections.Generic.List<int> vs1 = new System.Collections.Generic.List<int>();
            for (int i = 1; i <= a; i++)
            {
                if (a % i == 0)
                {
                    if (!vs.ContainsKey(a / i))
                    {
                        vs.Add(i, a / i);
                        var text = i + "和" + a / i + "  ";
                        num += text;
                        var t = i;
                        var t1 = a / i;

                        if (t > t1)
                        {
                            if (num1 >= t - t1)
                            {
                                num1 = t - t1;
                            }

                        }
                        if (t1 > t)
                        {
                            if (num1 >= t1 - t)
                            {
                                num1 = t1 - t;
                            }
                        }
                        sts = "最接近的因数是" + t1 + "和" + t;
                    }
                }
            }
            System.Console.WriteLine(num);

            System.Console.WriteLine(sts);

        }


        class ttt
        {
            public int id { get; set; }

            public string name { get; set; }
        }
        public static void getList()
        {
            List<ttt> vs = new List<ttt>();
            for (int i = 0; i < 10; i++)
            {
                vs.Add(new ttt
                {
                    id = i,
                    name = $"我是{i}"
                });
            }
            foreach (var item in vs)
            {
                item.name = "sdfad";
            }
            foreach (var item in vs)
            {
                System.Console.WriteLine(item.name);
            }
        }


        public static void GetInsertSQL()
        {
            StringBuilder strSql1 = new StringBuilder();

            strSql1.Append("insert into " + " eess " + "(");
            strSql1.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql1.Append(")");
            strSql1.Append("values");

            // 添加列
            strSql1.Append("Eqp_ID,");
            strSql1.Append("PC_ID,");
            strSql1.Append("OPERATION,");
            strSql1.Append("IS_TRANS,");
            strSql1.Append("TRAY_ID,");
            strSql1.Append("CELL_ID,");
            strSql1.Append("BATTERY_POS,");
            strSql1.Append("MODEL_NO,");
            strSql1.Append("BATCH_NO,");
            strSql1.Append("TOTAL_NG_STATE,");
            strSql1.Append("OCV_VOLTAGE,");
            strSql1.Append("ACIR,");
            strSql1.Append("TEST_NG_CODE,");
            strSql1.Append("TEST_RESULT,");
            strSql1.Append("TEST_RESULT_DESC,");
            strSql1.Append("PostiveSHELL_VOLTAGE,");
            strSql1.Append("PostiveSV_NG_CODE,");
            strSql1.Append("PostiveSV_RESULT,");
            strSql1.Append("PostiveSV_RESULT_DESC,");
            strSql1.Append("SHELL_VOLTAGE,");
            strSql1.Append("SV_NG_CODE,");
            strSql1.Append("SV_RESULT,");
            strSql1.Append("SV_RESULT_DESC,");
            strSql1.Append("POSTIVE_TEMP,");
            strSql1.Append("NEGATIVE_TEMP,");
            strSql1.Append("K,");
            strSql1.Append("V_DROP,");
            strSql1.Append("V_DROP_RANGE,");
            strSql1.Append("V_DROP_RANGE_CODE,");
            strSql1.Append("V_DROP_RESULT,");
            strSql1.Append("V_DROP_RESULT_DESC,");
            strSql1.Append("ACIR_RANGE,");
            strSql1.Append("R_RANGE_NG_CODE,");
            strSql1.Append("R_RANGE_RESULT,");
            strSql1.Append("R_RANGE_RESULT_DESC,");
            strSql1.Append("REV_OCV,");
            strSql1.Append("CAPACITY,");
            strSql1.Append("END_DATE_TIME,");
            strSql1.Append("TestMode,");
        }







        /// <summary>
        /// 图片生成
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static byte[] InserImage(string name)
        {  //新增图片，宽高为50
            Bitmap bt = new Bitmap(50, 50);
            //从指定的 Image 创建新的 Graphics。 绘画对象
            Graphics gh = Graphics.FromImage(bt);
            //填充背景色
            gh.Clear(Color.White);
            //设置字体颜色
            // DateTime dateTime = DateTime.Now();
            SolidBrush brush = new SolidBrush(Color.Black);
            /*
             * 
             * 在指定矩形并且用指定的 Brush 和 Font 对象绘制指定的文本字符串。
             * 
             *  gh.DrawString(绘制的字符串, 文本格式, 字体颜色, 左上角x坐标,左上角y坐标); 
             *  
             *  通过两个坐标确定文本再图片位置
             * 
             */
            gh.DrawString(name, new Font("宋体", 15), brush, 10, 10);
            //创建内存流
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            //图片写入流，绑定图片格式
            bt.Save(ms, ImageFormat.Jpeg);

            return ms.ToArray();

        }
    }
}
